package org.com.behavioralPattern.templateMethodPattern;

/**
 * 模板方法模式
 * @author Jonny
 * @version 1.0
 * @Description:
 * @date 2021/4/15 15:35
 */
public abstract class Account {
    //账号
    private String accountNumber;

    //构造函数
    public Account(){
        accountNumber=null;
    }

    public Account(String number){
        accountNumber=number;
    }

    //基本方法 确定账号类型
    protected abstract String getAccountType();
    //基本方法 确定利息
    protected abstract double getInterestRate();

    public double calculateAmount(String accountType,String accountNumber){
        //访问数据库得到一个值
        return 4567.0D;
    }

    //模板方法计算利息
    public double calculateInserest(){
        String accountType=getAccountType();
        double insertesRate=getInterestRate();
        double amount=calculateAmount(accountType,accountNumber);
        return amount*insertesRate;
    }

}
